﻿var xHRObject = false;
if (window.XMLHttpRequest) {
    xHRObject = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
    xHRObject = new ActiveXObject("Microsoft.XMLHTTP");
}
function sendRequest(data) {

    xHRObject.abort();
    document.getElementById("albumList").innerHTML = '<img src="../Images/wait.gif">';
    xHRObject.open("GET", "data.aspx?value=" + data, true);
    xHRObject.onreadystatechange = getData;
    xHRObject.send(null);
}
function sendVideoRequest(data) {

    xHRObject.abort();
    document.getElementById("recentVideoList").innerHTML = '<img src="../Images/wait.gif">';
    xHRObject.open("GET", "data.aspx?value=" + data, true);
    xHRObject.onreadystatechange = getData;
    xHRObject.send(null);
}

function sendSngRequest(data) {
    xHRObject.abort();
    document.getElementById("songList").innerHTML = '<img src="../Images/wait.gif">';
    xHRObject.open("GET", "data.aspx?sng=" + data, true);
    xHRObject.onreadystatechange = getData;
    xHRObject.send(null);
}

function sendPlayRequest(data,dataTitle,dataArtist){
    xHRObject.abort();
    document.getElementById("playSong").innerHTML = '<img src="../Images/wait.gif">';
    xHRObject.open("GET", "data.aspx?playSng=" + data + "&currentSngTitle="+dataTitle+"&currentArtist="+ dataArtist, true);
    xHRObject.onreadystatechange = getData;
    xHRObject.send(null);
}
function getData() {
    if (xHRObject.readyState == 4 && xHRObject.status == 200) {
        var serverText = xHRObject.responseText;
        if (serverText.indexOf('|') != -1) {
            element = serverText.split('|');

           // document.getElementById(element[1]).innerHTML = element[1];
            document.getElementById(element[0]).innerHTML = element[1];
            if (element[2] != null) {
                document.getElementById(element[2]).innerHTML = PaseAjaxResponse(element[3]);
            }
            if (element[4] != null) {
                document.getElementById(element[4]).innerHTML = element[5];
            }
        }
    }
}
function PaseAjaxResponse(somemixedcode) {
    var source = somemixedcode;
    var scripts = new Array();
    while (source.indexOf("<script") > -1 || source.indexOf("</script") > -1) {
        var s = source.indexOf("<script");
        var s_e = source.indexOf(">", s);
        var e = source.indexOf("</script", s);
        var e_e = source.indexOf(">", e);
        scripts.push(source.substring(s_e + 1, e));
        source = source.substring(0, s) + source.substring(e_e + 1);
    }
    for (var x = 0; x < scripts.length; x++) {
        try {
            eval(scripts[x]);
        }
        catch (ex) {
        }
    }
    return source;
}